//////////////////////////////////////////////////////
// Direct3D.h
//////////////////////////////////////////////////////

#pragma once

#include <d3d8.h>
#include <D3dx8tex.h>
#include "constants.h"


class CDirect3D
{
protected:
    LPDIRECT3D8 m_pD3D;
    LPDIRECT3DDEVICE8 m_pD3DDevice;
    IDirect3DSurface8* m_pBackBuffer;
    HWND m_hWnd;
    char m_szErrorMsg[256];
	IDirect3DSurface8* m_pTitleScreen; //Title Screen pointer 11-30-06
	IDirect3DSurface8* m_pTitleScreenOptions;
	IDirect3DSurface8* m_pTitleScreenQuit;
    IDirect3DSurface8* m_pTrainingGroundsSurfaces; //Training Grounds Surface (first area) 12-09-06
    IDirect3DSurface8* m_pCurrentTileSurface;
    IDirect3DTexture8* m_pPlayerTile;
    IDirect3DTexture8* m_pTexture;
    IDirect3DTexture8* m_pTitleScreenCursor;
	LPDIRECT3DTEXTURE8 g_lpTextures[NUM_SPRITES];
	LPDIRECT3DSURFACE8 lpSurface;


public:
    CDirect3D(void);
    ~CDirect3D(void);
    void SetWindowHandle(HWND hWnd);
    HRESULT InitD3D(void);
    LPDIRECT3DDEVICE8 GetDevice(void);
    IDirect3DSurface8* GetBackBuffer(void);
    char* GetErrorString(void);
	void InitBlit(); //intializes directX for blitting 1-1-07
	void Blit(IDirect3DTexture8* pTexture, POINT* pDest, D3DXVECTOR2* pCentre, 
          D3DXVECTOR2* pScaling = NULL, float angle = 0, D3DCOLOR colour = 0xFFFFFFFF);
//	void TransformVertices(D3DTLVERTEX vertices[], D3DXVECTOR2* pCentre, D3DXVECTOR2* pScaling, float angle)
	IDirect3DSurface8* GetTitleScreen(); //Title Screen function to get surface 11-30-06
	IDirect3DSurface8* GetTitleScreenOptions();
	IDirect3DSurface8* GetTitleScreenQuit();
    IDirect3DSurface8* GetTrainingGroundsSurfaces(); //get function 12-9-06
	LPDIRECT3DTEXTURE8 Getg_lpTextures(int whichbitmap); //getfunction 1-1-07
    IDirect3DSurface8* GetCurrentTileSurface();
    IDirect3DTexture8* GetPlayerTile();
    void SetCurrentTileSurface(IDirect3DSurface8* pSurface);
    IDirect3DTexture8* GetTexture();
    IDirect3DTexture8* GetTitleScreenCursor();
    void CleanUpEverythingElse(void);
	void CleanUpTitleScreen(void);
	void CleanUpTrainingGrounds(void);
	HRESULT CreateTitleScreenSurfaces(void);
	HRESULT CreateNonMapSurfaces(void);
	HRESULT CreateTrainingGroundsSurfaces();
	void CreateSurfaceFromFile(LPDIRECT3DSURFACE8* ppSurface, char szFileName[]);
	HRESULT CreateTextureFromSurface(IDirect3DSurface8* pSurface, RECT* pSrcRect,
                              LPDIRECT3DTEXTURE8* ppTexture);

private:
    HRESULT CreateD3DObject(void);
    HRESULT CheckDisplayMode(void);
    HRESULT CreateD3DDevice(void);
    

};
